<template>
  <div :class="className" :style="{height:height,width:width}" />
</template>

<script>
import echarts from 'echarts'
require('echarts/theme/macarons') // echarts theme
import resize from './mixins/resize'
import {dataObjInfos} from "../../api/system/index";
const animationDuration = 6000
import {optionsAction} from '@/api/statistics'
export default {
  mixins: [resize],
  props: {
    className: {
      type: String,
      default: 'chart'
    },
    width: {
      type: String,
      default: '98%'
    },
    height: {
      type: String,
      default: '350px'
    },
    autoResize: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      chart: null,
      objs:[],
      reports:[],
      matters:[],
      errs:[],
      deals:[],

      datas:{},
    }
  },
  mounted() {
    // this.loadData();
    this.$nextTick(() => {
      this.initData()
    })
  },
  beforeDestroy() {
    if (!this.chart) {
      return
    }
    this.chart.dispose()
    this.chart = null
  },
  methods: {
    initData(){
      optionsAction("warehouse_right").then(response=>{
        this.datas =  response.data;
      }).finally(()=>{
         this.initChart()
      })
    },
    // loadData(){
    //   dataObjInfos().then(response => {
    //     if(response.data != null && response.data.length > 0){
    //       let objs = [];
    //       let reports = [];
    //       let matters = [];
    //       let deals = [];
    //       let errs = [];
    //       response.data.forEach(function(item){
    //         objs.push(item.name);
    //         if(item.rcounts != null){
    //           reports.push(item.rcounts);
    //         }else{
    //           reports.push(0);
    //         }
    //         if(item.mcounts != null){
    //           matters.push(item.mcounts);
    //         }else{
    //           matters.push(0);
    //         }
    //         if(item.dcounts != null){
    //           deals.push(item.dcounts);
    //         }else{
    //           deals.push(0);
    //         }
    //         if(item.ecounts != null){
    //           errs.push(item.ecounts);
    //         }else{
    //           errs.push(0);
    //         }
    //       });
    //       this.reports = reports;
    //       this.matters = matters;
    //       this.deals = deals;
    //       this.objs = objs;
    //       this.errs =  errs;
    //     }
    //   }).finally(() => {
    //     this.initChart()
    //   });
    // },
    initChart() {
      this.chart = echarts.init(this.$el, 'macarons');
      var option;
      option = {
        legend: {
            left: 'right'
          },
        // color:['#73c0de','#91cc75', '#fac858','#5470c6','#9a60b4','#3ba272',  '#ee6666',  '#fc8452', '#ea7ccc'],
        color: ['#37A2FF', '#00DDFF','#73c0de','#80FFA5', '#FF0087', '#FFBF00'],
        tooltip: {
          trigger: 'axis',
          axisPointer: {
            type: 'cross',
            label: {
              backgroundColor: '#6a7985'
            }
          }
        },
        grid: {
          left: '1%',
          right: '3%',
          bottom: '2%',
          containLabel: true
        },
        xAxis: [
          {
            type: 'category',
            boundaryGap: false,
            // data: ["沙县区","清流县","永安市","宁化县","大田县","沙县区","市管理中心"],
            data:this.datas.xData
          }
        ],
        yAxis: [
          {
            // show:false,
            type: 'value'
          }
        ],
        series:this.datas.yData
        // series: [
        //   {
        //     name: '货币',
        //     type: 'line',
        //     stack: 'Total',
        //     smooth: true,
        //     areaStyle: {},
        //     emphasis: {
        //       focus: 'series'
        //     },
        //     data: [120, 132, 101, 134, 90, 230, 210]
        //   },
        //   {
        //     name: '违禁品',
        //     type: 'line',
        //     stack: 'Total',
        //     smooth: true,
        //     areaStyle: {},
        //     emphasis: {
        //       focus: 'series'
        //     },
        //     data: [220, 182, 191, 234, 290, 330, 310]
        //   },
        //   {
        //     name: '贵重物品',
        //     type: 'line',
        //     stack: 'Total',
        //     smooth: true,
        //     areaStyle: {},
        //     emphasis: {
        //       focus: 'series'
        //     },
        //     data: [150, 232, 201, 154, 190, 330, 410]
        //   }
        // ]
      };
      this.chart.setOption(option);
    }
  }
}
</script>
